/**
 * 
 */
package com.miolr.core.service.local;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import javax.inject.Inject;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.miolr.core.dao.GenericDao;
import com.miolr.core.query.PageModel;
import com.miolr.core.service.GenericService;

/**
 * @author iday
 *
 */
public class LocalGenericService<D extends GenericDao<T>, T> implements GenericService<D, T> {

	protected D dao;

	@Inject
	public void setDao(D dao) {
		this.dao = dao;
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public List<T> queryAll(DetachedCriteria detachedCriteria, PageModel pm,
			boolean cached, String cacheRegion) {
		return dao.queryAll(detachedCriteria, pm, cached, cacheRegion);
	}
	
	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public List<T> queryAll(PageModel pm,
			boolean cached, String cacheRegion) {
		return dao.queryAll(pm, cached, cacheRegion);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public List<T> queryAll(String sql, PageModel pm) {
		return dao.queryAll(sql, pm);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public List<T> queryAll(String sql, PageModel pm, boolean cached) {
		return dao.queryAll(sql, pm, cached);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public List<T> queryAll(String sql) {
		return dao.queryAll(sql);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public List<T> queryAll(String sql, boolean cached) {
		return dao.queryAll(sql, cached);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public List<T> findAll() {
		return dao.findAll();
	}
	
	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public T findByPrimaryKey(Serializable key) {
		return dao.findByPrimaryKey(key);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void deleteAll(Collection<T> c) {
		dao.deleteAll(c);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void delete(T obj) {
		dao.delete(obj);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void deleteByPrimaryKey(Serializable key) {
		dao.deleteByPrimaryKey(key);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void saveOrUpdate(Collection<T> c) {
		dao.saveOrUpdate(c);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void merge(T t) {
		dao.merge(t);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void update(T obj) {
		dao.update(obj);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void save(T obj) {
		dao.save(obj);
	}

}
